home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-09 | 927 b | 45 lines | [TEXT/CWIE] |
- //
- // CObjectMaker.h
- //
- // Template class CObjectMaker
- // A template for C++ classes that construct and auto-destruct QuickDraw 3D objects.
- //
- // This is an abstract class.
- // Everything is inline, so there is no *.cp file.
- //
- // by James Jennings
- // November 26, 1995
- //
-
- #pragma once
-
- // A useful inline function.
- inline
- void Q3Forget( TQ3Object & inObject )
- {
- if ( inObject != 0 )
- ::Q3Object_Dispose( inObject );
- inObject = 0;
- }
-
- template <class T>
- class CObjectMaker {
- protected:
- CObjectMaker() : mObject(0) {}
- virtual ~CObjectMaker() { Q3Forget( mObject ); }
-
- virtual void Make() = 0;
- public:
- T Get() const
- { // Get() is normally a const function,
- // unless Make() does a defered change.
- if (!mObject)
- const_cast<CObjectMaker<T>*>(this)->Make();
- return mObject;
- }
- T GetRef() const
- { return ::Q3Shared_GetReference( Get() ); }
- protected:
- T mObject;
- };
-